import apiClient from './apiClient'

export const categoryService = {
  // 获取分类分页列表
  getCategoryList: async (params) => {
    return await apiClient.get('/categories', { params })
  },

  // 获取所有分类
  getAllCategories: async () => {
    return await apiClient.get('/categories')
  },

  // 获取启用分类
  getActiveCategories: async () => {
    return await apiClient.get('/categories/active')
  },

  // 根据ID获取分类
  getCategoryById: async (id) => {
    return await apiClient.get(`/categories/${id}`)
  },

  // 创建分类
  createCategory: async (categoryData) => {
    return await apiClient.post('/categories', categoryData)
  },

  // 更新分类
  updateCategory: async (id, categoryData) => {
    return await apiClient.put(`/categories/${id}`, categoryData)
  },

  // 删除分类
  deleteCategory: async (id) => {
    return await apiClient.delete(`/categories/${id}`)
  },

  // 更新分类状态
  updateCategoryStatus: async (id, status) => {
    return await apiClient.patch(`/categories/${id}/status`, { status })
  },

  // 获取分类总数
  getCategoryCount: async () => {
    return await apiClient.get('/categories/count')
  },

  // 搜索分类
  searchCategories: async (keyword, type) => {
    const params = {};
    if (keyword) params.keyword = keyword;
    if (type) params.type = type;
    return await apiClient.get('/categories/search', { params })
  }
}